home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 August / August CD.bin / Shareware / Education / numericalmethods Folder / chap_5 / cs.m < prev    next >
Encoding:
Text File  |  1994-06-05  |  533 b   |  29 lines  |  [MATF/MATL]

  1. function Z = cs(S,X,T)
  2. % Z = cs(S,X,T)
  3. % Evaluates the spline created with csfit.m
  4. % S coefficient list, input.
  5. % X is the vector of abscissas, input.
  6. % T is the input value(s), input.
  7. % Z is the function value(s), output.
  8. n = length(X)-1;
  9. m = length(T);
  10. Z = zeros(1,m);
  11. for i=1:m,
  12.   t = T(i);
  13.   j = 0;
  14.   k = n-1;
  15.   while (j<=n-1);
  16.     j=j+1;
  17.     if (t<=X(j+1)),
  18.       k=j-1;
  19.       j=n+1;
  20.     end
  21.   end
  22.   if (t<=X(1)),
  23.     k = 0;
  24.   end
  25.   w = t-X(k+1);
  26.   z=((S(k+1,3+1)*w + S(k+1,2+1))*w + S(k+1,1+1))*w + S(k+1,0+1);
  27.   Z(i) = z;
  28. end
  29.